package cn.kgc.crowdfundingadminspringboot2.controller;

import cn.kgc.crowdfundingadminspringboot2.common.ResultEntity;
import cn.kgc.crowdfundingadminspringboot2.pojo.Advertisement;
import cn.kgc.crowdfundingadminspringboot2.service.AdvertisementService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/advertisement")
public class AdvertisementController {
    @Resource
    AdvertisementService advertisementService;
    @RequestMapping("/query/for/search")
    @ResponseBody
    public ResultEntity<PageInfo<Advertisement>> queryforsearch( @RequestParam(value = "pageNum", defaultValue = "1",required = false) Integer pageNum,
                                                                 @RequestParam(value = "pageSize", defaultValue = "5",required = false) Integer pageSize,
                                                                 @RequestParam(value = "keyword", defaultValue = "",required = false) String keyword){
        PageInfo<Advertisement> info = advertisementService.queryAll(pageNum, pageSize, keyword);
        ResultEntity<PageInfo<Advertisement>> pageInfoResultEntity = ResultEntity.successWithoutData(info);
        return pageInfoResultEntity;
    }


    @ResponseBody
    @RequestMapping("/get/list/by/id/list")
    public ResultEntity<Advertisement> getRoleListByIdList(@RequestBody Integer roleIdList) {
        Advertisement adminById = advertisementService.getAdminById(roleIdList);
        return ResultEntity.successWithoutData(adminById);
    }
    @ResponseBody
    @RequestMapping("/batch/remove")
    public ResultEntity<String> batchRemove(@RequestBody List<Integer> roleIdList) {
        advertisementService.batchRemove(roleIdList);
        return ResultEntity.successWithoutData();
    }



    @ResponseBody
    @RequestMapping("/save/advertisement")
    public ResultEntity<String> saveRole(@RequestParam("advertisement") Advertisement advertisement) {

        advertisementService.saveAdvertisement(advertisement);

        return ResultEntity.successWithoutData();
    }

    @ResponseBody
    @RequestMapping("/update/role")
    public ResultEntity<String> updateRole(Advertisement advertisement) {

       advertisementService.updateAdmin(advertisement);

        return ResultEntity.successWithoutData();
    }
}
